import sympy as sp
import numpy as np

# 定义符号变量
x, y = sp.symbols('x y', real=True)

# 定义原函数
smooth_solution2_expr = x * (x - 1) * y * (y - 1) * sp.exp(-x**2 - y**2)

# 计算偏导
smooth_solution2_dx_expr = sp.diff(smooth_solution2_expr, x)
smooth_solution2_dy_expr = sp.diff(smooth_solution2_expr, y)

# 将符号表达式转成可计算的 numpy 函数
smooth_solution2_dx = sp.lambdify((x, y), smooth_solution2_dx_expr, modules=['numpy'])
smooth_solution2_dy = sp.lambdify((x, y), smooth_solution2_dy_expr, modules=['numpy'])

# 打印解析解（简化后）
print("∂f/∂x =", sp.simplify(smooth_solution2_dx_expr))
print("∂f/∂y =", sp.simplify(smooth_solution2_dy_expr))

